package fpzhan.plane.program.proxy;

import com.alibaba.fastjson.JSONObject;
import fpzhan.plane.program.manager.JsonKeyManager;
import fpzhan.plane.program.compose.ComposeContent;
import fpzhan.plane.program.compose.ComposeContext;

import java.math.BigDecimal;
import java.util.Set;

public class SpeedProxy extends CodeBlockProxy{


    public SpeedProxy(String proxyName ) {
        super(proxyName, 1);
    }

    @Override
    public JSONObject before(ComposeContext composeContext, ComposeContent composeContent, Set<String> keys ,  JSONObject json) throws Exception {
        JSONObject obj = new JSONObject();
        obj.put("startTime",System.currentTimeMillis());
        return obj;
    }

    @Override
    public void after(JSONObject before, ComposeContext composeContext,  ComposeContent composeContent,  Set<String> keys , JSONObject json) throws Exception {
        long startTime = (long)before.get("startTime");
        json.put(JsonKeyManager.getJsonKey().flowRunSpeedKey, BigDecimal.valueOf(System.currentTimeMillis()).subtract(BigDecimal.valueOf(startTime)).intValue());
    }
}
